package com.logistics.version.entity.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.tool.StringUtils;
import com.logistics.version.entity.model.VersionSave;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
@TableName("lgs_version")
public class Version implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String appName;

    private String versionName;

    private Integer versionCode;

    private String versionPath;

    private String fileName;

    private String targetFileName;

    private String versionContext;

    private String creator;

    private Date createTime;

    private String updater;

    private Date updateTime;

    private String createOrgCode;

    private String createDepCode;

    public Version(){}

    public Version(VersionSave save){
        this.id = StringUtils.isNotNull(save.getId()) ? Integer.parseInt(save.getId()) : null;
        this.appName = save.getAppName();
        this.versionName = save.getVersionName();
        this.versionCode = StringUtils.isNotNull(save.getVersionCode()) ? Integer.parseInt(save.getVersionCode()) : 0;
        this.fileName = save.getFileName();
        this.targetFileName = save.getTargetFileName();
        this.versionContext = save.getVersionContext();
        this.creator = save.getCreator();
        this.createTime = DateUtils.stringToDateFormat(save.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
        this.createOrgCode = save.getCreateOrgCode();
        this.createDepCode = save.getCreateDepCode();
        this.updater = save.getUpdater();
        this.updateTime = DateUtils.stringToDateFormat(save.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
    }

    public static Version build(VersionSave save){
        return new Version(save);
    }
}
